<?php

require_once(dirname(__FILE__).'/Config.php');

class Garden_Controller {
    public  $mode = '';
    public  $stash = array();
    private $mode_param  = 'mode';
    public  $validations = array();
    public  $templates   = array();
    public  $assign      = array();
    public  $param;
    private $template;

    function __construct () {
        $this->param = array_merge($_POST, $_GET);
        $this->template = '';
    }

    function mode ($mode = null) {
        if ($mode !== null) {
            $this->mode = $mode;
        }
        return $this->mode;
    }

    function display () {
        # check authorization
        # get user

        if ($this->conditions) {
            $this->determine_mode();
        }

        if ($this->templates) {
            $this->set_template();
        }

        if ($this->assign) {
            $this->assign_params();
        }

        print 1;
    }

    private function validate_params ($mode = null) {
        if (isset($mode) && isset($this->validations[$mode]) {
            $param_rules = $this->validations[$mode];
            foreach ($param_rules as $param => $rules) {
                $validator = new Garden_Validator($param, $rules);
                $validator->check();
            }
        }
        else if (isset($this->validations['_default'])) {
            $param_rules = $this->validations['_default'];
            foreach ($param_rules as $params => $rules) {
                $validator = new Garden_Validator($param, $rules);
                $validator->check();
            }
        }
        return 1;
    }

    private function determine_mode () {
        $mode = $this->mode;
        $this->validate_params($mode);
    }

    private function set_template () {
    }

    private function assign_params () {
    }
}

